<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Users extends MY_Admin
{
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function Users()
	{
		parent::MY_Admin();
		
		// Load required classes
		$this->load->model('users_model', 'users');
		
		// Template Settings
		$this->template->metas('title', 'Administration Backend :: Users');
	}

	// --------------------------------------------------------------------
	
	/**
	 * List all users
	 *
	 * @access	public
	 */
	function index()
	{
		$data['users'] = $this->users->get_all_users();		
		$data['content'] = $this->load->view('admin/users/list', $data, TRUE);
		
		$this->template->display('admin/users/list', $data);
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Remove a user
	 *
	 * @param	integer	id of the user to remove
	 * @access	public
	 */
	function remove($id)
	{
		confirm('Do you really want to delete this user and all his entries?');
				
		// Superadmin id == 1
		if ($id === '1')
		{
			// @TODO: Style have to go in a CSS stylesheet, not mixed in code
			$this->session->set_flashdata('msg', '<b style="color: #800;">Superadmin cannot be deleted</b>');
			redirect('admin/users');
		}
		else if ($this->user->id !== '1' AND $this->access->get_group($id) === 'Administrators')
		{
			show_error('You do not have permission to delete other Administrators.');
		}
		
		$this->load->model('listings_model', 'listings');
		
		$this->listings->delete_user_entries($id);
		$this->users->delete($id);
		
		$this->session->set_flashdata('msg', 'User Deleted');
		redirect('admin/users');
	}
}

/* End of file users.php */
/* Location: ./application/controllers/admin/users.php */